﻿using System;
using EmbeddedSharp.Core;
using EmbeddedSharp.Scripting;
using Zove.Runtime;

namespace Zove.Scripting.Modelling {

    /// <summary>
    /// Assume a factor is known
    /// </summary>
    [Function("assume", "Assume a factor is known", "circle c;\nassume(c.r);\narea=formulate(c.area);", "area==3.14*c.r^2")]
    public class AssumeNode : ZoveScriptingContextFuncNode {

        public AssumeNode()
            : base("assume") {
        }

        public override object Evaluate() {
            int length = Parameters.Count;
            if (length < 1) {
                throw new ArgumentException(
                    "usage: assume(factorName)");
            }

            string factorName = Parameters[0].Value;
            RuntimeFactor factor
                = ZoveShellContext.GetFactor(
                factorName);
            if (factor == null) {
                throw new FactorNotDeclaredException(
                    factorName);
            }

            factor.Initialize(0);

            return factor;
        }
    }
}
